<% layout('/layouts/default.html', {title: '来文登记表管理', libs: ['validate']}){ %>
<style>
    .form-error{
        color: white;
    }
</style>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header with-border">
            <div class="box-title">
                <i class="fa icon-note"></i> ${text('确定还文信息' )}


            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            </div>
        </div>
        <#form:form id="inputForm" model="${docRecv}" action="${ctx}/sd/docDeliverReturn/returnFile" method="post" class="form-horizontal">
        <div class="box-body">
            <div class="form-unit">${text('基本信息')}</div>
            <#form:hidden path="id"/>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('来文标题')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="docTitle" maxlength="500" readonly="true" class="form-control required"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('来文文号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="docFullNum" readonly="true" maxlength="100" class="form-control required"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('来文自编号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="docSysCode" readonly="true" maxlength="100" class="form-control required"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('紧急程度')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select path="docEmergLvl" readonly="true" dictType="recv_doc_emerg_lvl"  class="form-control required" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('密级')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select path="secLvl" readonly="true" dictType="recv_sec_lvl" class="form-control required" />
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('来文日期')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="docRecvDate" readonly="true" maxlength="20" class="form-control  required"
                            dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6" >
                    <div class="form-group">

                        <label class="control-label col-sm-4" title="" >
                            <span class="required ">*</span> ${text('还文人选择')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8" id="opt">
                                <#form:select path="moduleCodes" onchange="getUser()" items="${empList}" itemLabel="empName" id="user" itemValue="empCode" blankOption="true" class="form-control " />
                                <#form:input path="showUserId" onfocus="get()" placeholder="输入还文人姓名或挑选还文人"  onblur="left()" id="showUserId" class="form-control required" style="position: absolute;top:0px;width:80%"  />
                                <#form:input path="userCode" id="userCode" class="form-control" style="position: absolute;top:0px;width:80%" type="hidden" />

                            <input name="doi" id="doid" type="hidden" value=${doid}>
                        </div>


                            <div class="col-sm-3" style="display: none;" id="faceShow">
                                <!--   <i style="position: absolute;cursor:pointer;left: 72px;top: 20px" title="拍照" onclick="collectPicture()" class="icon-cloud-upload"></i> -->
                                <!--   <img style="height: 50px;cursor: pointer;border-radius: 50px" id="showImg" src="${ctxStatic}/camera.jpg"  title="预览" onclick="jumpLayer()">-->
                                <a href="#" class="btn btn-default camera" id="lrFace"   title="录入人脸" onclick="collectPicture()"><i class="icon-camera"></i></a>
                            </div>
                    </div>
                    <div >
                    </div>





                </div>

              <!-- <i style="position: absolute;left: 520px ;margin-left: 10%;display: none" id="faceShow">
                    <img style="height: 50px;cursor: pointer;border-radius: 50px" id="showImg" src="${ctxStatic}/camera.jpg" class="img-responsive fa icon-note" title="拍照" onclick="collectPicture()">
                </i>-->
                        <div class="col-xs-6"  >
                            <div class="form-group">
                                <label class="control-label col-sm-4" title="">
                                    <span class="required ">*</span> ${text('领文人警号')}：<i class="fa icon-question hide"></i></label>
                                <div class="col-sm-8">
                                    <#form:input path="policeCode"  id="policeCode" readonly="true" maxlength="20" class="form-control  required" />
                                    <#form:input path="face" id="pictureSrc" type="hidden" readonly="true" maxlength="20" class="form-control" />
                                </div>
                            </div>
                        </div>

                    </div>
           <!-- <div class="col-xs-11" id="faceShow" style="display: none">
                <div class="form-group">
                    <label class="control-label col-sm-2">
                    </label>
                    <div class="col-sm-8">
                        <a href="#" class="btn btn-default camera"  title="点击录入人脸" onclick="collectPicture()"><i class="icon-camera"></i></a>


                    </div>
                </div>
            </div>-->
                </div>

                    </div>

                </div>
                <div class="box-footer">
                    <div class="row">
                        <div class="col-sm-offset-2 col-sm-10" style="">
                            <% if (hasPermi('sd:docRecv:edit')){ %>
                            <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
                            <%}%>
                            <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                        </div>
                    </div>

                </div>

            </#form:form>
        </div>
    </div>
    <% } %>
    <script>
        var facepath;

  //       function jumpLayer() {
  // if(facepath=="1"){
  //     facepath="${ctxStatic}/camera.jpg"
  // }
  //
  //         js.layer.open({
  //             type:3,
  //             area: ['550px', '550px'],
  //             title:"预览",
  //             content:"<img src="+facepath+">",
  //             /*btn:['拍照','关闭'],
  //             btn1:function (index,layero) {
  //              collectPicture();
  //             },
  //             btn2:function () {
  //               js.layer.closeAll()
  //             }*/
  //         })
  //       }
        function getUser(){
            var str=$("#user").val();
            $("#showUserId").val($("#user option:checked").text())
            $("#userCode").val(str)
            if (str!=""){
                $.ajax({
                    type: "POST",
                    url: "${ctx}/sd/docDeliverTake/selectUserInfor",
                    data:{"userCode":str},
                    success: function (data) {
                        $("#policeCode").val(data)
                        document.getElementById("policeCode").setAttribute("readonly","true")

                    }

                })
            }else{
                $("#policeCode").val("")

            }





        }
        var i=0;
        var len;
        function get(){
            len=$("#showUserId").val();
        }
        function left(){
            if($("#showUserId").val()!=len){

                $("#policeCode").val("")
                $("#policeCode").removeAttr("readonly")
               // js.layer.msg("请录入人脸信息")
                //collectPicture()
                $("#faceShow").css("display","block")
                $("#opt").attr("class","col-xs-6");
                $("#faceShow").attr("class","col-xs-2")
                if(i==0){
                    $("#pictureSrc").val(1)
                }


                i=i+1;
            }
        }
        function collectPicture(){
            js.layer.open({
                type: 2,
                area: [(js.layer.window.outerWidth-350)+'px',(js.layer.window.outerHeight-200)+'px'],
                title: '${text("拍照")}',
                resize: false,
                scrollbar: true,
                maxmin:true,
                content: '${ctx}/sd/collectPicture/form',
                success: function(layero, index){

                },
                btn: ['<i class="fa fa-check"></i> ${text("上传")}',
                    '<i class="fa fa-remove"></i> ${text("关闭")}'],
                btn1: function (index, layero) {
                    var win = layero.iframeWindow();
                    if (typeof(win.getFile()) == "undefined"){
                        js.layer.msg('请先拍照再提交!', {icon: 5});
                        return false;
                    }
                    console.log(typeof (win.getFile()));
                    var formData = new FormData;
                    formData.append("file", win.getFile());
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/sd/collectPicture/uploadFile",
                        data: formData,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                            if(data.result===Global.TRUE){
                                js.layer.msg(data.message, {icon: 1});
                                js.layer.close(index);
                                $('#pictureSrc').val(data.data);
                                facepath=win.getUrl();
                                $("#lrFace").attr("onclick","reset()")
                                $("#lrFace").attr("title","预览照片")
                              //  $("#showImg").attr("src",facepath)

                              //     $("#showImg").attr("onclick","reset()")
                              //  js.layer.alert("<img src="+ win.getFiles()+" >")
                                return true;
                            }else {
                                js.layer.msg(data.message, {icon: 5});
                                return false;
                            }

                        }
                    })
                    return false;

                }


            });
        }
function reset(){
    js.layer.confirm("<div> <img src="+facepath+"  style='height: 300px;'> </div>",{
        title : "预览",
        skin : "my-skin",
        btn : [ '重拍', '取消' ],
        yes:function () {
          collectPicture();
        }

    })
}
        $("#inputForm").validate({
            submitHandler: function(form){
                js.ajaxSubmitForm($(form), function(data){
                    //alert($("#pictureSrc").val())
                       if($("#pictureSrc").val()=="1"){
                           js.layer.msg("请录入人脸信息",{icon:5})
                           return false;
                       }
                      // alert($("#showUserId").val())

                    if($("#showUserId").val()==""){
                        js.layer.msg("请输入姓名",{icon:5})
                        return false;
                    }
                    js.showMessage(data.message);
                    if(data.result == Global.TRUE){
                        window.location.href="${ctx}/sd/docDeliverReturn/list";
                       /* js.closeCurrentTabPage(function(contentWindow){
                            alert("1")





                        });*/
                    }
                }, "json");
            }
        });

window.onload=function () {
    facepath=1;
}
    </script>
